package demo18;

import java.util.concurrent.TimeUnit;

class MyThread extends Thread{
    @Override
    public void run() {
        // 模拟酸的时间比较久
        try {
            TimeUnit.SECONDS.sleep(5);
        }catch (InterruptedException exc){
            exc.printStackTrace();
        }

        synchronized (demo.class) {
            demo.result = 100;
            demo.class.notify();
        }
    }
}

public class demo {
    static long result = -1;

    public static void main(String[] args) throws InterruptedException {
        MyThread thread = new MyThread();
        thread.start();

        // 等待子线程算完
        long r;
        synchronized (demo.class){
            while (result == -1) {
                demo.class.wait();
            }
            r = result;
        }

        System.out.println(r);
    }
}
